cmake_minimum_required(VERSION 3.5)

project(qcustomPlot LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

#用来编译ui文件
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# 调试模式编译
set(CMAKE_BUILD_TYPE DEBUG)
add_definitions(-g)

#指定输出目录
# set(OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../bin)
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${OUTPUT_PATH})
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${OUTPUT_PATH})
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${OUTPUT_PATH})
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${OUTPUT_PATH})

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 传统版本OpenGL
# set(OpenGL_GL_PREFERENCE GLVND)
# 新版OpenGL
set(OpenGL_GL_PREFERENCE LEGACY)
# 使用openGL
add_definitions(-DQCUSTOMPLOT_USE_OPENGL)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

# 这里添加了，target_link_libraries也需要同步添加
set(Qt_pkg 
    Core
    Gui
	Widgets
	LinguistTools 
	Multimedia
	PrintSupport
    SerialPort
)

find_package(QT NAMES Qt6 Qt5 COMPONENTS ${Qt_pkg} REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${Qt_pkg} REQUIRED)

find_package(OpenGL REQUIRED)

set(TS_FILES qcustomPlot_zh_CN.ts)


# 创建缓存目录
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../Cache)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../Model)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../Data)

# 设定自定义库路径
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
link_directories(${LIBRARY_OUTPUT_PATH})

#资源文件
set(QRC_FILES
    pic.qrc
)
qt5_add_resources(QRC_HEADERS ${QRC_FILES})

# qt_add_resources(QRC_FILES ${QRC_SOURCE_FILES})
# SOURCE_GROUP("Resource Files" FILES ${QRC_SOURCE_FILES})

# if(ANDROID)
#   add_library(qcustomPlot SHARED
#     main.cpp
#     mainwindow.cpp
#     mainwindow.h
#     mainwindow.ui
#     ${TS_FILES}
#   )
# else()

# 查找cpp文件
# set(SRC_LIST test.cpp)
# aux_source_directory(${PROJECT_SOURCE_DIR} SRC)
# file(GLOB SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 
file(GLOB_RECURSE SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 

# 查找ui文件,设定CMAKE_AUTOUIC_SEARCH_PATHS的路径，
# 自动查找.ui文件，解决.cpp和.ui不在同一个目录的问题
file(GLOB UI_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ui/*.ui)
# file(GLOB UI_INCLUDE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ui/*.h)
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/ui)
#message("UI_FILES:" ${UI_FILES})
# 查找头文件
file(GLOB_RECURSE INCLUDE_FILES 
       ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
       ${CMAKE_CURRENT_SOURCE_DIR}/DSPFilters/include/DspFilters/*.h

)
# 仿真服务器cpp分开编译
list(REMOVE_ITEM SRC_FILES 
    ${CMAKE_CURRENT_SOURCE_DIR}/src/simulationServer/SimulationServer.cpp
)

# list(REMOVE_ITEM INCLUDE_FILES 
#     ${CMAKE_CURRENT_SOURCE_DIR}/include/emotion_src/TCPClient.h
# )
# message("SRC_FILES: " ${SRC_FILES})
# 引入头文件
include_directories(
	${CMAKE_CURRENT_SOURCE_DIR}/include
	${CMAKE_CURRENT_SOURCE_DIR}/include/emotion
	${CMAKE_CURRENT_SOURCE_DIR}/include/collectData
	${CMAKE_CURRENT_SOURCE_DIR}/include/emotion_src
	${CMAKE_CURRENT_SOURCE_DIR}/include/stateMonitorWidget
	${CMAKE_CURRENT_SOURCE_DIR}/include/emoRecognize
	${CMAKE_CURRENT_SOURCE_DIR}/include/simulationServer
	${CMAKE_CURRENT_SOURCE_DIR}/include/DropoutDetection
    ${CMAKE_CURRENT_SOURCE_DIR}/DSPFilters/include
	${CMAKE_CURRENT_SOURCE_DIR}/DSPFilters/include/DspFilters
)
# # 生成ui文件对应的头文件
# qt5_wrap_ui(UI_HEADERS ${UI_FILES})

# 设置可执行文件输出路径
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)

# message(inc: ${INCLUDE_FILES})
# message(INCLUDE_FILES:${INCLUDE_FILES})
add_executable(emotion_gui
	${SRC_FILES}
	${UI_FILES}
	${INCLUDE_FILES}

	# ${UI_HEADERS}
    ${QRC_HEADERS}
    ${TS_FILES}

	# ffmpeg/ffmpeg.h
	# ffmpeg/ffmpeg.cpp
)
# endif()

target_link_libraries(emotion_gui 
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Gui
    Qt${QT_VERSION_MAJOR}::Multimedia
    Qt${QT_VERSION_MAJOR}::PrintSupport
    Qt${QT_VERSION_MAJOR}::SerialPort
    #avcodec
    avcodec 
    #av_dict
    avformat avutil  
    # sws_scale
    swresample swscale
    # armadillo
    armadillo
    #thread
    pthread 
    # thread
    OpenGL::GL

    DSPFilters
)

# 虚拟服务器，用于模拟信号采集

add_executable(sim_eegDev
    ${CMAKE_CURRENT_SOURCE_DIR}/src/simulationServer/SimulationServer.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/src/ConfigImport.cpp


    ${CMAKE_CURRENT_SOURCE_DIR}/include/simulationServer/SimulationServer.h
    ${CMAKE_CURRENT_SOURCE_DIR}/include/ConfigImport.h


    # ${QRC_HEADERS}
    ${TS_FILES}
)
target_link_libraries(sim_eegDev
    # armadillo
    armadillo
)


qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})

# message("CMAKE_SOURCE_DIR" ${CMAKE_SOURCE_DIR})
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
qt5_create_translation(QM_FILES ${TS_FILES} ${CMAKE_SOURCE_DIR} )


# if(WIN32)
# set(Qt5_DIR "F:\\Qt\\Qt5.12.10\\5.12.10\\mingw73_64\\lib\\cmake\\Qt5")
# get_target_property(Qt5Core_location Qt5::Core LOCATION)
# message(STATUS "Qt5 Core file: ${Qt5Core_location}")

# #message(STATUS "Qt5 Core file: $<TARGET_FILE:Qt5::Core>")
# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
#      COMMAND ${CMAKE_COMMAND} -E copy_if_different
#      $<TARGET_FILE:Qt5::Core> $<TARGET_FILE_DIR:${PROJECT_NAME}>
#      # $<TARGET_FILE:Qt5::Gui> $<TARGET_FILE_DIR:${PROJECT_NAME}>
#      $<TARGET_FILE:Qt5::Widgets> $<TARGET_FILE_DIR:${PROJECT_NAME}>
# )
# add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
#      COMMAND ${CMAKE_COMMAND} -E copy_directory
#      ${Qt5_DIR}/../../../plugins/platforms $<TARGET_FILE_DIR:${PROJECT_NAME}>/platforms
#      # ${TS_FILES} $<TARGET_FILE_DIR:${PROJECT_NAME}>
# )
# endif()


